Imports System.configuration

Partial Class LoginBox
    Inherits System.Web.UI.UserControl

    Private _dbconn As IDataStore = New XmlManipulator("Default")
    Private _pv As PageView = New PageView

    Protected Sub btnLogin_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles btnLogin.Click

        Dim uName As String = txtUserName.Text
        Dim pWord As String = txtPassword.Text
        Dim vName As String = ""

        If uName = "" Then

            lblMessage.Text = "Please enter your username."
            lblMessage.Visible = True
            Exit Sub
        Else

            If pWord = "" Then

                lblMessage.Text = "Please enter your password."
                lblMessage.Visible = True
                Exit Sub
            Else

                vName = _dbconn.ValidateUser(uName, pWord)

            End If
        End If

        If vName = "" Then

            lblMessage.Text = "Username or password incorrect, please try again."
            lblMessage.Visible = True
            Exit Sub

        Else

            _pv.UserName = vName
            Response.Redirect(ConfigurationManager.AppSettings("redirectPage"))

        End If

    End Sub

End Class
